<template>
	<sc-contextmenu-item
		:command="button.code"
		:title="button.name"
		:suffix="button.suffix"
		:icon="button.icon"
		:disabled="disabled"
		:divided="button.divided"
		:color="button.color"
		:button="button"
	>
		<ButtonIcon
			v-for="btn in button.children"
			:button="btn"
			v-bind:key="btn.id"
			:gridEvents="gridEvents"
			:grid="grid"
		>
		</ButtonIcon>
	</sc-contextmenu-item>
</template>
<script>
import scContextmenuItem from "@/components/scContextmenu/item";
export default {
	name: "ButtonIcon",
	components: {
		scContextmenuItem,
	},
	emits: ["handleClick"],
	props: {
		button: {},
		gridEvents: {},
		grid: {},
	},
	data() {
		return {
			disabled: false,
		};
	},

	mounted() {
		this.setButtonStatue(this.button.selectRecords?.length ?? 0);
	},
	methods: {
		setButtonStatue(selectRecordsLen) {
			if (
				typeof this.gridEvents["disable_" + this.button.code] ==
				"function"
			) {
				let disable = this.gridEvents["disable_" + this.button.code]({
					button: this.button,
					grid: this.grid,
				});
				if (disable === true || disable === false) {
					this.disabled = disable;
					return;
				}
			}

			switch (this.button.model_id) {
				case 1:
					this.disabled = selectRecordsLen == 1 ? false : true;

					break;
				case 2:
					this.disabled = selectRecordsLen >= 1 ? false : true;
					break;
				case 3:
					break;
			}
		},
	},
};
</script>
<style scope></style>
